<!--  -->
<template>
  <div class="shop-coupon"  @click.stop="goDetail(couponItem)" 
    :class="[(selected == 2 || selected == 3)?'shop-gray':'']">
    <!--couponItem.can_spread?'shop-mg':'',-->
    <div class="coupon-content" :class="[couponItem.can_spread?'shop-mg-pg':'',couponItem.api_limit?'shadow-bg':'']" >
      <div class="coupon-bg"></div>
      <div :class="[couponItem.can_spread?'shop-mg':'']">
        <div class="shop-background" :style="`background: linear-gradient(180deg, rgba(${coThemeColor},0.3) 0%, #FFFFFF 100%);`"></div>
      </div>
      <!--:style="`background: linear-gradient(180deg, rgba(${coThemeColor},0.9) 0%, #FFFFFF 100%);`"-->
      <div v-if="couponItem.can_spread" class="shop-after" ></div>
      <div v-if="couponItem.can_spread" class="shop-before"></div>
      <van-swipe-cell>
        <div class="shop-couponNew flex-a-c" >
          <slot name="tag"></slot>
          <div class="left flex-j-c">
            <template v-if="couponItem.belongs_to_coupon && couponItem.belongs_to_coupon.coupon_method == 1">
              <h3><span>{{ $i18n.t("money") }}</span>{{ parseFloat(couponItem.belongs_to_coupon.deduct) || '0' }}</h3>
              <p>满{{ couponItem.belongs_to_coupon.enough }}可用</p>
            </template>
            <template v-if="couponItem.belongs_to_coupon && couponItem.belongs_to_coupon.coupon_method == 2">
              <h3>{{ parseFloat(couponItem.belongs_to_coupon.discount) || '-' }}折</h3>
              <p>满{{ couponItem.belongs_to_coupon.enough }}立享</p>
            </template>
            <template v-if="couponItem.coupon_method == 1">
              <h3><span>{{ $i18n.t("money") }}</span>{{ parseFloat(couponItem.deduct) || '0' }}</h3>
              <p>满{{ couponItem.enough }}可用</p>
            </template>
            <template v-if="couponItem.coupon_method == 2">
              <h3>{{ parseFloat(couponItem.discount) || '-' }}折</h3>
              <p>满{{ couponItem.enough }}立享</p>
            </template>
          </div>
          <div class="coupon-wrap flex-j-c">
            <div class="coupon-circle"></div>
            <div class="coupon-circle2"></div>
              <div class="flex flex-j-sb">
                <h3 class="center-title ell">{{ couponItem.name }}</h3>
                <slot name="couponBtn"></slot>
              </div>
              <h3 class="title ell" >{{ couponItem.belongs_to_coupon && couponItem.belongs_to_coupon.name }}</h3>
              <slot name="assign"></slot>
              <div class="assign-shop flex-a-c flex-j-sb" :class="couponItem.isIntegralExchange?'integral-flex':''">
                <div class="shop" v-if="couponItem.belongs_to_coupon && couType != 1">{{ couponItem.belongs_to_coupon && couponItem.belongs_to_coupon.coupon_type_name }}</div>
                <div class="shop" v-if="couponItem.coupon_type_name ">{{ couponItem.coupon_type_name }}</div>
                <slot name="integral"></slot>
                <slot name="moreUp"></slot>
                <slot name="moreDown"></slot>
              </div>
              <slot name="time"></slot>
              <slot name="assignNum"></slot>
              <slot name="status"></slot>
              <slot name="numCount"></slot>
          </div>
        </div>
        <template #right v-if="deleteShow">
          <van-button square type="danger" text="删除" style="height: 100%;" @click.stop="delteteItem(couponItem, index)" />
        </template>
      </van-swipe-cell>
    </div>
    <div v-if="couponItem.can_spreadShow">
      <block  v-for="(itemChild,childIndex) in couponItem.can_spreadShow_list" :key="childIndex">
        <coupon-cell
          :index="childIndex"
          :couponItem="itemChild" 
          :combineshow="combine_show" 
          :selected="selected" 
          :deleteShow="deleteShow" 
          v-on="$listeners">
          <template #tag>
            <div class="tag" v-if="itemChild.combine && itemChild.num != 1">{{ itemChild.num }}张</div>
            <div class="tag iseff" v-if="!itemChild.is_effective && selected == 1">待生效</div>
          </template>
          <template #time>
            <p class="coupon-time" >{{ itemChild.time_start }}-{{ itemChild.time_end }}</p>
          </template>
        </coupon-cell>
      </block>
    </div>
    <slot name="explain"></slot>
  </div>
</template>

<script>
  //这里可以导入其他文件（比如：组件，工具js，第三方插件js，json文件，图片文件等等）
  //例如：import 《组件名称》 from '《组件路径》';
export default {
  props: {
    selected: {
      type: Number || String
    },
    couponItem:{
      type:Object,
      default:() => {
        return {}
      }
    },
    //表示我的优惠券，兑换中心，优惠券中心的参数，方便隐藏多余的信息
    couType:Number,
    index:Number,
    combine_show: {
      type: null
    },
    coThemeColor:{
      type: Number || String
    },
    deleteShow:Boolean
  },
  name:'couponCell',
  //import引入的组件需要注入到对象中才能使用
  components: {},
  data() {
  return {
  };
  },
  //监听属性 类似于data概念
  computed: {},
  //监控data中的数据变化
  watch: {},
  //方法集合
  methods: {
    delteteItem(couponItem, index) {
      console.log(couponItem);
      console.log(index);
      this.$emit("delItem", {item:couponItem,index:index});
    },
    goDetail(couponItem) {
      this.$emit('goDetail', {item:couponItem});
    }
  },
  //生命周期 - 创建完成（可以访问当前this实例）
  created() {

  },
  //生命周期 - 挂载完成（可以访问DOM元素）
  mounted() {
  },
  beforeCreate() {}, //生命周期 - 创建之前
  beforeMount() {}, //生命周期 - 挂载之前
  beforeUpdate() {}, //生命周期 - 更新之前
  updated() {}, //生命周期 - 更新之后
  beforeDestroy() {}, //生命周期 - 销毁之前
  destroyed() {}, //生命周期 - 销毁完成
  activated() {}, //如果页面有keep-alive缓存功能，这个函数会触发
}
</script>
<style lang="scss" scoped>
/* @import url(); 引入公共css类 */
.ell {
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  /* 定义显示的行数 */
  overflow: hidden;
}
.shop-coupon {
    margin:0 0 0.625rem 0;
    position: relative;
    border-radius: 0.625rem;
    .coupon-content {
      border-radius: 0.625rem 0.625rem 0.625rem 0.625rem;
      position: relative;
      z-index: 2;
      background-color: #fff;
    }
    .shop-after {
      width:calc(100% - 1.125rem);
      height: 100%;
      background: #fff;
      // background: linear-gradient(298deg, var(--themeBaseColor) 0%, #FFFCFC 100%);
      border-radius: 0.625rem 0.625rem 0.625rem 0.625rem;
      height: 5.625rem;
      position: absolute;
      top:0.25rem;
      left:0.5625rem;
      z-index: -2;
      // opacity: 0.8;
      &::before {
        content: "";
        position: absolute;
        top: -50%;
        bottom: -50%;
        left: -50%;
        right: -50%;
        transform: scale(0.5);
        border: solid 0.0625rem var(--themeBaseColor);
        border-radius: 1.25rem 1.25rem 1.25rem 1.25rem;
        box-sizing:border-box;
        opacity: 0.1;
        
      }
    }
    .shop-before {
      width:calc(100% - 3rem);
      height: 100%;
      // background: linear-gradient(298deg, var(--themeBaseColor) 0%, #FFFCFC 100%);
      background: #fff;
      border-radius: 0.625rem 0.625rem 0.625rem 0.625rem;
      height: 5.625rem;
      position: absolute;
      top:0.5rem;
      left:1.5rem;
      z-index: -3;
      // opacity: 0.8;
      &::before {
        content: "";
        position: absolute;
        top: -50%;
        bottom: -50%;
        left: -50%;
        right: -50%;
        transform: scale(0.5);
        border: solid 0.0625rem var(--themeBaseColor);
        border-radius: 1.25rem 1.25rem 1.25rem 1.25rem;
        box-sizing:border-box;
        opacity: 0.1;
      }
    }
    
    .shop-couponNew {
      border-radius: 0.625rem;
      height: 5.625rem;
      position: relative;
      .tag {
        color: #FFFFFF;
        font-size: 0.75rem;
        line-height: 0.75rem;
        padding:0.1875rem 0.375rem;
        position:absolute;
        left:0;
        top:0;
        border-radius: 0.625rem 0rem 0.5rem 0rem;
        background: var(--themeBaseColor);
      }
      .iseff {
        color:#fff;
        background: #B6B6B6;
      }
      .left {
        width:30%;
        height: calc(100% - 1.0625rem);
        flex-direction: column;
        position: relative;
        border-right: 0.0625rem dashed #D6D6DC;
        // padding:0 1.5rem;
        min-width: 6.875rem;
        margin:0.5625rem 0 0.5rem 0;
        h3 {
          color:var(--themeBaseColor);
          font-weight: bold;
          font-size: 1.5rem;
          span {
            font-size: 0.8125rem;
          }
        }
        p {
          color: var(--themeBaseColor);
          font-size: 0.75rem;
        }
        
      }
      .coupon-wrap {
        width:70%;
        height: 100%;
        flex-direction: column;
        padding:0 0.75rem;
        flex:1;
        position: relative;
        .coupon-circle {
          content:'';
          position: absolute;
          width: 0.5rem;
          height: 0.5rem;
          background-color: #F5F5F5;
          border-radius: 50%;
          top:-0.25rem;
          left:-0.3438rem;
          z-index: -1;
          
        }
        .coupon-circle2 {
          content:'';
          position: absolute;
          width: 0.5rem;
          height: 0.5rem;
          background-color: #F5F5F5;
          border-radius: 50%;
          bottom:-0.25rem;
          left:-0.3438rem;
          z-index:1;
        }
        .title,.center-title {
          text-align: left;
          font-size: 0.875rem;
          font-weight: bold;
          color: #00001C;
        }
        .center-title {
          // width:70%;
        }
        .assign-shop {
          padding:0.375rem 0 0 0;
          .shop {
            font-size: 0.75rem;
            line-height: 0.75rem;
            padding:0.1875rem 0.3125rem;
            border-radius: 0.3125rem 0.3125rem 0.3125rem 0.3125rem;
            position: relative;
            color: var(--themeBaseColor);
            &::after {
              content: '';
              width:100%;
              height: 100%;
              background: var(--themeBaseColor);
              opacity: 0.15;
              position: absolute;
              z-index: 0;
              left:0;
              top:0;
              border-radius: 0.3125rem 0.3125rem 0.3125rem 0.3125rem;
            }
          }
          .more {
            color: #6E6E79;
            font-size: 0.75rem;
            .iconfont {
              margin:0 0 0 0.25rem;
              font-size: 0.75rem;
            }
          }
        }
        .coupon-time {
          font-size: 0.75rem;
          color: #6E6E79;
          padding:0.3125rem 0 0 0;
          text-align: left;
        }
        .dueBox {
          color: #AAAAB3;
          font-size: 0.75rem;
          text-align: left;
        }
      }
    }
    .integral-flex {
      justify-content: flex-start;
    }
    
  }
  .shop-gray {
    .shop-couponNew {
      .left {
        h3,p {
          color:#6E6E79;
        }
      }
      .coupon-wrap {
        .title {
          color:#6E6E79;
        }
        .assign-shop {
          .shop {
            color:#AAAAB3;
            &::after {
              background-color: #AAAAB3;
            }
          }
        }
        .coupon-time {
          color:#AAAAB3;
        }
        
      }
    }
  }
  .shop-mg-pg {
    // &::after {
    //   content: '';
    //   opacity: 0.8;
    // }
    .shop-background {
      width:100%;
      height: 100%;
      background-color: rgba(255,255,255,0.8);
      // background: linear-gradient(180deg, var(--themeBaseColor) 0%, #FFFFFF 100%);
      
      position: absolute;
      z-index: -1;
      left:0;
      top:0;
      border-radius: 0.625rem;
    }
    &::before {
      content: "";
      position: absolute;
      top: -50%;
      bottom: -50%;
      left: -50%;
      right: -50%;
      transform: scale(0.5);
      border: solid 0.0625rem var(--themeBaseColor);
      border-radius: 1.25rem 1.25rem 1.25rem 1.25rem;
      box-sizing:border-box;
      z-index: 0;
      opacity: 0.6;
    }
    .shop-couponNew {
      .coupon-wrap {
        .coupon-circle {
          &::before {
            content: "";
            position: absolute;
            top: -50%;
            bottom: -50%;
            left: -50%;
            right: -50%;
            transform: scale(0.5);
            border: solid 0.0625rem var(--themeBaseColor);
            box-sizing:border-box;
            border-radius: 50%;
          }
          // &::after {
          //   content:'';
          //   width: 10px;
          //   height: 10px;
          //   background: var(--themeBaseColor);
          //   border-radius: 50%;
          //   top:0;
          //   left:0;
          //   position: absolute;
          //   z-index: 0;
          // }
        }
        .coupon-circle2 {
          // background: linear-gradient(180deg, var(--themeBaseColor) 0%, #FFFFFF 100%);
          background-color: #fff;
          &::before {
            content: "";
            position: absolute;
            top: -50%;
            bottom: -50%;
            left: -50%;
            right: -50%;
            transform: scale(0.5);
            border: solid 0.0625rem var(--themeBaseColor);
            box-sizing:border-box;
            border-radius: 50%;
          }
        }
      }
    }
    
  }
  .shop-mg-pg {
    margin:0 0 1.125rem 0;
  }
  .shadow-bg {
    box-shadow: 0rem 0.1875rem 0.5rem 0.0625rem rgba(240,240,241,1);
  }
</style>